home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / windows / mrun211.zip / MRUN211G.WAS < prev    next >
Text File  |  1993-05-01  |  45KB  |  1,685 lines

  1. ;MailRun v2.11:  Part G, domailrun
  2. ;1992-1993 Gerald P. Sully, all rights reserved.
  3.  
  4. #COMMENT
  5. **************************************************************************
  6. **************************************************************************
  7. * The following procedures form the engine of the script.  First
  8. * makedir() is called to create a dialing directory for BBSs listed
  9. * in the *.MRN file that have pending items.  Each BBS is called,
  10. * and on connection, each pending item listed for that BBS is executed
  11. * by dobbs().  These tasks are performed by sendmail(), getmail(),
  12. * ulfile(), dlfile(), and sendcommand().  As each task is completed,
  13. * the task list window is updated.
  14. * While online, the key procedure is holding() which keeps track of the
  15. * length of time the board has been inactive, checks for dropped carrier
  16. * and obtains the current line from the terminal screen so that it can
  17. * be parsed by the various procedures that respond to prompts.  The
  18. * latter include checkbaseset(), checkcommandprompt(), checkmailprompt()
  19. * and the like.
  20. **************************************************************************
  21. **************************************************************************
  22. #ENDCOMMENT
  23.  
  24. #define MRUN211G
  25. #define MRUN211AG
  26.  
  27. #define GOTOFILE 1
  28. #define GOTOMAIN 0
  29.  
  30. string MainBoxTabs, prompt
  31. integer xferstatus, holdstatus, foundstatus
  32.  
  33. #include "MRUN211.h"
  34.  
  35.  
  36. #comment
  37. *********************************************************************
  38. * MAIN()
  39. * Calls menudim(), checkchild(), maketasklist(), dobbs()
  40. * mailrunbox(), parsedialog(), makequeue(), readbbs(),
  41. * makefullname(), findstring(), capturescreen()
  42. * Main first calls the initialization routines, then puts
  43. * up the main dialog box and dispatches each requested
  44. * action.
  45. *********************************************************************
  46. #endcomment
  47.  
  48. proc main
  49. string DialString, PhoneNum, ComString, ComMsg, BBSName
  50. string  CnctFail1, CnctFail2, CnctFail3, CnctFail4, CnctFail5
  51. string char
  52. integer ComStringLength
  53. integer Attempts, MaxAttempts, DialOutTime, RingInterrupt
  54. integer i, j, n
  55. integer FirstCall
  56.     menudim()
  57.     checkchild()
  58.     profilerd MailRunIni "MailRun" "MailRunDir" MailRunDir
  59.     TaskList = makefullname(TempDir, "TASKLIST.TMP")
  60.     findfirst MailRun
  61.     MailRunTrunc = $FILENAME
  62.     maketasklist()
  63.     mailrunbox()
  64.     makequeue()
  65.     ;interface is turned on by makequeue
  66.     when dialog call parsedialog
  67.     profilerd MailRun "MailRun" "LogRun" LogRun
  68.     if LogRun
  69.         profilerd MailRun "MailRun" "AnsiInLog" AnsiInLog
  70.         if AnsiInLog
  71.             set capture mode append RAW
  72.         else
  73.             set capture mode append VISUAL
  74.         endif
  75.         capture ON
  76.     endif
  77.     profilerd MailRun "MailRun" "DialAttempts" MaxAttempts
  78.     fetch modem nocnct1 CnctFail1
  79.     fetch modem nocnct2 CnctFail2
  80.     fetch modem nocnct3 CnctFail3
  81.     fetch modem nocnct4 CnctFail4
  82.     fetch modem nocnct5 CnctFail5
  83.     Attempts = 1
  84.     FirstCall = 1
  85.     while Attempts <= MaxAttempts
  86.         itoa Attempts AttemptNum
  87.         updatedlg 64
  88.         ;Keep dialing until the maximum number of attempts has been made
  89.         ;reread MaxAttempts on each loop in case the user changes settings
  90.         profilerd MailRun "MailRun" "DialAttempts" MaxAttempts
  91.         n = 1
  92.         DialString = getdialstring(&n)
  93.         if n == 0
  94.             exitwhile
  95.         endif
  96.         while not NULLSTR DialString
  97.             ;Loop until all numbers have been called
  98.             set aspect rxdata ON
  99.             rxflush
  100.             if FirstCall != 1
  101.                 ;Don't pause if this is the first call in the loop
  102.                 profilerd MailRun "MailRun" "DialPause" j
  103.                 profilerd MailRun "MailRun" "RingInterrupt" RingInterrupt 
  104.                 while j > 0
  105.                     statmsg "Last Message:  %s      Pausing  %d" ComMsg j
  106.                     pause 1
  107.                     j--
  108.                     ComStringLength = $RXCOUNT
  109.                     comgets ComString ComStringLength
  110.                     if RingInterrupt && findstring(ComString, "RING")
  111.                         capturescreen()
  112.                         capturestr \
  113.                             "`r`n`r`n**** Interrupted by Incoming Call ****`r`n`r`n"
  114.                         statmsg "Mailrun interrupted by incoming call"
  115.                         capture OFF
  116.                         exit
  117.                     endif
  118.                 endwhile
  119.             else
  120.                 FirstCall = 0
  121.             endif
  122.             ;Dial the BBS
  123.             strextract PhoneNum DialString "`t" 0
  124.             strextract char DialString "`t" 1
  125.             atoi char i
  126.             BBS = readbbs(i)
  127.             profilerd MailRun BBS "BBSName" BBSName
  128.             strfmt ComString "ATDT%s`r" PhoneNum
  129.             strlen ComString ComStringLength
  130.             computs ComString ComStringLength
  131.             ;rxdata must be on in order to get characters from the modem
  132.             ComString = ""
  133.             ComMsg = ""
  134.             profilerd MailRun "MailRun" "DialTimeOut" DialOutTime
  135.             while (!$CARRIER) && (DialOutTime > 0)
  136.                 ;Loop until a connection is made, timeout is reached, or a
  137.                 ;negative connect message is received
  138.                 ComStringLength = $RXCOUNT
  139.                 comgets ComString ComStringLength
  140.                 if strfind ComString CnctFail1
  141.                     ComMsg = CnctFail1
  142.                     exitwhile
  143.                 elseif strfind ComString CnctFail2
  144.                     ComMsg = CnctFail2
  145.                     exitwhile
  146.                 elseif strfind ComString CnctFail3
  147.                     ComMsg = CnctFail3
  148.                     exitwhile
  149.                 elseif strfind ComString CnctFail4
  150.                     ComMsg = CnctFail4
  151.                     exitwhile
  152.                 elseif strfind ComString CnctFail5
  153.                     ComMsg = CnctFail5
  154.                     exitwhile
  155.                 endif
  156.                 rxflush
  157.                 statmsg "Dialing %s      %s     Waiting %d" \
  158.                     PhoneNum BBSName DialOutTime
  159.                 pause 1
  160.                 DialOutTime--
  161.             endwhile
  162.             set aspect rxdata OFF
  163.             if DialOutTime == 0
  164.                 ;If dial timed out...
  165.                 hangup
  166.                 ComMsg = "TIMEOUT"
  167.             endif
  168.             if $CARRIER
  169.                 ;if connected to a BBS...
  170.                 statmsg "Connected to %s" BBSName
  171.                 dobbs()
  172.                 makequeue()
  173.                 statmsg ""
  174.                 FirstCall = 1
  175.                 n--
  176.             endif
  177.             n++
  178.             DialString = getdialstring(&n)
  179.         endwhile
  180.         Attempts++
  181.     endwhile
  182.     capture OFF
  183.     statmsg ""
  184. endproc
  185.  
  186.  
  187. #comment
  188. *********************************************************************
  189. * DOBBS()
  190. * Called by main()
  191. * Calls readitem(), writeitem(), sendscript(), logoff(), fileexit()
  192. * maketasklist(), gettaskstring(), getcommandprompt(),
  193. * getmail(), sendmail(), dlfile(), ulfile(), sendcommand(),
  194. * Dispatches pending tasks for the BBS to which MailRun
  195. * is connected.
  196. *********************************************************************
  197. #endcomment
  198.  
  199. proc dobbs
  200. string Pending, TaskType, BBSName, BBSType
  201. integer FailCode, j
  202.     ;Return to this point with a FailCode of 1 if carrier
  203.     ;is lost or the BBS times out
  204.     Failcode = 0
  205.     setjmp ErrorFail FailCode
  206.     if FailCode == 0
  207.         profilerd MailRun BBS "BBSType" BBSType
  208.         profilerd MailRun BBS "BBSName" BBSName
  209.         profilerd MailRun "MailRun" "IdleTimeout" IdleTimeout
  210.         ;Assume login to Conference 0
  211.         CurrentConf = "0"
  212.         Conf = "0"
  213.         ;Highlight the current BBS in the task list
  214.         TaskItem = gettaskstring(BBS, 0)
  215.         updatedlg 16
  216.  
  217.         ;The first item must be read before the first holding()
  218.         ;(which occurs in getcommandprompt()) in case an error occurs.
  219.         j = 1
  220.         Item = readitem(BBS, j)
  221.         getcommandprompt()
  222.         while not NULLSTR Item
  223.             ;Loop through each Item for this BBS
  224.             TaskItem = gettaskstring(BBS, j)
  225.             updatedlg 16
  226.             strextract Pending Item "," 0
  227.             if strcmpi Pending "1"
  228.                 ;If the item is pending, execute it
  229.                 strextract TaskType Item "," 2
  230.                 switch TaskType
  231.                     case "GetMail"
  232.                         statmsg "Getting Mail Packet"
  233.                         getmail()
  234.                     endcase
  235.                     case "SendMail"
  236.                         statmsg "Sending Reply Packet"
  237.                         sendmail()
  238.                     endcase
  239.                     case "GetFile"
  240.                         statmsg "Downloading File"
  241.                         dlfile()
  242.                     endcase
  243.                     case "SendFile"
  244.                         statmsg "Uploading File"
  245.                         ulfile()
  246.                     endcase
  247.                     case "SendCommand"
  248.                         statmsg "Sending Command"
  249.                         sendcommand()
  250.                     endcase
  251.                     case "SendScript"
  252.                         statmsg "Executing Script"
  253.                         sendscript()
  254.                     endcase
  255.                 endswitch
  256.                 ;Update the task list
  257.                 TaskItem = gettaskstring(BBS, j)
  258.                 writeitem(BBS, j, Item)
  259.                 taskfilefwd(TaskItem)
  260.                 TaskItem = gettaskstring(BBS, j)
  261.                 fputs TaskFile TaskItem
  262.                 taskfileend()
  263.                 ItemR--
  264.                 updatecount()
  265.                 updatedlg 80
  266.             endif
  267.             j++
  268.             Item = readitem(BBS, j)
  269.         endwhile
  270.         getcommandprompt()
  271.     else
  272.         ;If timeout or loss of carrier
  273.         ;Change unfinished items to errors
  274.         while not NULLSTR Item
  275.             strextract Pending Item "," 0
  276.             if strcmpi Pending "1"
  277.                 strupdt Item "2" 0 1
  278.                 writeitem(BBS, j, Item)
  279.             endif
  280.             j++
  281.             Item = readitem(BBS, j)
  282.         endwhile
  283.         maketasklist()
  284.         j--
  285.         Item = readitem(BBS, j)
  286.         TaskItem = gettaskstring(BBS, j)
  287.         updatedlg 80
  288.     endif
  289.     statmsg "Logging off"
  290.     logoff()
  291.     if $CARRIER
  292.         ;If still connected after logoff...
  293.         errormsg "Unable to drop carrier; aborting..."
  294.         ;abort the mailrun
  295.         fileexit()
  296.     endif
  297. endproc
  298.  
  299.  
  300. #comment
  301. *********************************************************************
  302. * MAKEQUEUE()
  303. * Called by main(), parsedialog()
  304. * Calls openfile(), readbbs(), checkpending(),
  305. * interfaceon(), interfaceoff(), makefullname()
  306. * Creates a file of phone numbers for BBSs that have
  307. * pending items in the current mailrun.
  308. *********************************************************************
  309. #endcomment
  310.  
  311. proc makequeue
  312. string PhoneNum, Number_X, QueueList, BBSid
  313. integer i, j
  314.     interfaceoff()
  315.     QueueList = makefullname(TempDir, "QUEUE.TMP")
  316.     openfile(QueueListFile, QueueList, _CREATE, _NORMAL)
  317.     i = 1
  318.     BBSid = readbbs(i)
  319.     ;Loop through each BBS
  320.     while not NULLSTR BBSid
  321.         if checkpending(BBSid)
  322.             ;If the BBS has pending items...
  323.             j = 1
  324.             strfmt Number_X "Number_%d" j
  325.             profilerd MailRun BBSid Number_X PhoneNum
  326.             ;Loop through each phone number
  327.             while not NULLSTR PhoneNum
  328.                 fstrfmt QueueListFile "%s`t%d`r`n" PhoneNum i
  329.                 j++
  330.                 strfmt Number_X "Number_%d" j
  331.                 profilerd MailRun BBSid Number_X PhoneNum
  332.             endwhile
  333.         endif
  334.         i++
  335.         BBSid = readbbs(i)
  336.     endwhile
  337.     fclose QueueListFile
  338.     interfaceon()
  339. endproc
  340.  
  341.  
  342. #comment
  343. *********************************************************************
  344. * GETDIALSTRING()
  345. * Called by main()
  346. * Calls makefullname(), interfaceon(), interfaceoff(),
  347. * openfile()
  348. * Gets a DialString from the queue.  The string contains
  349. * a phone number and a bbs coordinate.
  350. *********************************************************************
  351. #endcomment
  352.  
  353. func getdialstring : string
  354. intparm n
  355. integer i
  356. string DialString, QueueList
  357.     interfaceoff()
  358.     DialString = ""
  359.     QueueList = makefullname(TempDir, "QUEUE.TMP")
  360.     openfile(QueueListFile, QueueList, _READWRITE, _TEXT)
  361.     i = 1
  362.     while i <= n
  363.         fgets QueueListFile DialString
  364.         if NULLSTR DialString
  365.             n = 0
  366.             exitwhile
  367.         endif
  368.         i++
  369.     endwhile
  370.     fclose QueueListFile
  371.     interfaceon()
  372.     return DialString
  373. endfunc
  374.  
  375.  
  376. #comment
  377. *********************************************************************
  378. * GETCOMMANDPROMPT()
  379. * Called by dobbs(), getconfprompt(), getotherprompt(),
  380. * ulfile(), dlfile(), sendcommand(), sendscript()
  381. * Calls holding(), checkcommandprompt()
  382. * Responds to prompts until the "Command" prompt is received.
  383. *********************************************************************
  384. #endcomment
  385.  
  386. proc getcommandprompt
  387.     when quiet 1 call checkcommandprompt
  388.     holding()
  389.     clearwhen quiet
  390. endproc
  391.  
  392.  
  393. #comment
  394. *********************************************************************
  395. * CHECKCOMMANDPROMPT()
  396. * Called by getcommandprompt()
  397. * Calls checkbaseset(), findstring(), endhold()
  398. * Checks the prompt and sends the appropriate response.
  399. *********************************************************************
  400. #endcomment
  401.  
  402. proc checkcommandprompt
  403. string NamePrompt, UserName, BBSType
  404. string PWordPrompt, PWord, FilePrompt
  405. string MailPrompt, CommandPrompt, MsgMenuPrompt
  406.     profilerd MailRun BBS "BBSType" BBSType
  407.     profilerd MailRun BBS "NamePrompt" NamePrompt
  408.     profilerd MailRun BBS "PWordPrompt" PWordPrompt
  409.     profilerd MailRun BBS "FilePrompt" FilePrompt
  410.     profilerd MailRun BBS "MailPrompt" MailPrompt
  411.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  412.     profilerd MailRun BBS "MsgMenuPrompt" MsgMenuPrompt
  413.     if !(checkbaseset())
  414.         if findstring(prompt, MailPrompt) || \
  415.             (findstring(BBSType, "WildCat") && \
  416.             findstring(prompt, MsgMenuPrompt))
  417.             transmit "q^M"
  418.         elseif findstring(BBSType, "WildCat") && \
  419.             findstring(prompt, "Join conference")
  420.             transmit Conf
  421.             transmit "^M"
  422.         elseif findstring(prompt, NamePrompt)
  423.             profilerd MailRun BBS "UserName" UserName
  424.             transmit UserName
  425.             transmit "^M"
  426.         elseif findstring(prompt, PWordPrompt)
  427.             profilerd MailRun BBS "PWord" PWord
  428.             transmit PWord
  429.             transmit "^M"
  430.         elseif findstring(prompt, "Escape") || findstring(prompt, " ESC ")
  431.             ;send escape character
  432.             computc 0x1B
  433.           if findstring(prompt, "twice") || findstring(prompt, "two")
  434.                 ;pause 50 milliseconds
  435.                 mspause 50
  436.                 computc 0x1B
  437.             endif
  438.         elseif findstring(prompt, CommandPrompt) || \
  439.             findstring(prompt, FilePrompt)
  440.             endhold()
  441.         endif
  442.     endif
  443. endproc
  444.  
  445.  
  446. #comment
  447. *********************************************************************
  448. * GETCONFPROMPT()
  449. * Called by ulfile(), dlfile()
  450. * Calls getcommandprompt(), findstring()
  451. * Changes conferences if necessary.
  452. *********************************************************************
  453. #endcomment
  454.  
  455. proc getconfprompt
  456. string BBSType
  457.     profilerd MailRun BBS "BBSType" BBSType
  458.     if not strcmpi CurrentConf Conf
  459.         ;If we have to change conferences...
  460.         if findstring(BBSType, "WildCat")
  461.             transmit "j^M"
  462.         elseif findstring(BBSType, "PCBoard")
  463.             transmit "j;"
  464.             transmit Conf
  465.             transmit "^M"
  466.         endif
  467.         getcommandprompt()
  468.         CurrentConf = Conf
  469.     endif
  470. endproc
  471.  
  472.  
  473. #comment
  474. *********************************************************************
  475. * CHECKMAILPROMPT()
  476. * Called by getmail(), sendmail()
  477. * Calls endhold(), findstring(), checkbaseset()
  478. * Opens the mail door and gets the mail prompt.
  479. *********************************************************************
  480. #endcomment
  481.  
  482. proc checkmailprompt
  483. string MailPrompt, CommandPrompt, MailDoor, FilePrompt
  484. string BBSType, MsgMenuPrompt
  485.     profilerd MailRun BBS "BBSType" BBSType
  486.     profilerd MailRun BBS "MsgMenuPrompt" MsgMenuPrompt
  487.     profilerd MailRun BBS "MailPrompt" MailPrompt
  488.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  489.     profilerd MailRun BBS "FilePrompt" FilePrompt
  490.     if !(checkbaseset())
  491.         if findstring(BBSType, "WildCat") && \
  492.             (findstring(prompt, CommandPrompt) || findstring(prompt, FilePrompt))
  493.             transmit "M^M"
  494.         elseif findstring(prompt, MailPrompt)
  495.             endhold()
  496.         elseif (findstring(prompt, CommandPrompt) && \
  497.             (findstring(BBSType, "PCBoard") || findstring(BBSType, "RBBS"))) || \
  498.             (findstring(BBSType, "WildCat") && findstring(prompt, MsgMenuPrompt))
  499.             profilerd MailRun BBS "MailDoor" MailDoor
  500.             transmit MailDoor
  501.             transmit "^M"
  502.         endif
  503.     endif
  504. endproc
  505.  
  506.  
  507. #comment
  508. *********************************************************************
  509. * CHECKDESCPROMPT()
  510. * Called by ulfile(), dlfile()
  511. * Calls findstring(), endhold(), checkbaseset()
  512. * Checks for presense of the upload description prompt.
  513. * Sets promptstatus to 0 if the file already on the board.
  514. *********************************************************************
  515. #endcomment
  516.  
  517. proc checkdescprompt
  518. string ULDescPrompt, DLUnavPrompt, CommandPrompt, FilePrompt, BBSType
  519.     profilerd MailRun BBS "BBSType" BBSType
  520.     profilerd MailRun BBS "ULDescPrompt" ULDescPrompt
  521.     profilerd MailRun BBS "DLUnavPrompt" DLUnavPrompt
  522.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  523.     profilerd MailRun BBS "FilePrompt" FilePrompt
  524.     if !(checkbaseset())
  525.         if findstring(prompt, "file # 2") || findstring(prompt, "file #2") || \
  526.             findstring(prompt, "Keywords? [")
  527.             transmit "^M"
  528.         elseif (findstring(BBSType, "WildCat") && \
  529.             (findstring(prompt, "password protect") || \
  530.             findstring(prompt, "detailed") || \
  531.             findstring(prompt, "last download"))) || \
  532.             (findstring(BBSType, "RBBS") && \
  533.             findstring(prompt, "Extended description"))
  534.             transmit "n^M"
  535.         elseif findstring(prompt, "after upload")
  536.             transmit "c^M"
  537.         elseif findstring(BBSType, "RBBS") && findstring(prompt, "To A)ll")
  538.             transmit "a^M"
  539.             foundstatus = 1
  540.             endhold()
  541.         elseif findstring(prompt, ULDescPrompt)
  542.             foundstatus = 1
  543.             endhold()
  544.         elseif findstring(prompt, DLUnavPrompt) || \
  545.             findstring(prompt, "file # 1") || findstring(prompt, "file #1") || \
  546.             findstring(prompt, CommandPrompt) || findstring(prompt, FilePrompt)
  547.             if findstring(BBSType, "Auntie") && !(findstring(prompt, FilePrompt))
  548.                 transmit "q^M"
  549.             endif
  550.             foundstatus = 0
  551.             endhold()
  552.         endif
  553.     endif
  554. endproc
  555.  
  556.  
  557. #comment
  558. *********************************************************************
  559. * GOTULDLPROMPT()
  560. * Called by ulfile()
  561. * Releases the hold when the upload prompt is received.
  562. *********************************************************************
  563. #endcomment
  564.  
  565. proc gotuldlprompt
  566.     foundstatus = 1
  567.     endhold()
  568. endproc
  569.  
  570.  
  571. #comment
  572. *********************************************************************
  573. * GETOTHERPROMPT()
  574. * Called by sendmail(), getmail(), ulfile(), dlfile(),
  575. * sendcommand(), sendscript()
  576. * Calls findstring(), getcommandprompt()
  577. * For BBSs with a separate File prompt, moves to or from
  578. * the prompt.
  579. *********************************************************************
  580. #endcomment
  581.  
  582. proc getotherprompt
  583. intparm gotoplace
  584. string FilePrompt, BBSType
  585.     profilerd MailRun BBS "BBSType" BBSType
  586.     profilerd MailRun BBS "FilePrompt" FilePrompt
  587.     if !(findstring(prompt, FilePrompt)) && (gotoplace == GOTOFILE)
  588.         transmit "f^M"
  589.     elseif findstring(prompt, FilePrompt) && (gotoplace == GOTOMAIN)
  590.         transmit "q"
  591.         if findstring(BBSType, "RBBS")
  592.             transmit ";m"
  593.         endif
  594.         transmit "^M"
  595.     endif
  596.     getcommandprompt()
  597. endproc
  598.  
  599.  
  600. #comment
  601. *********************************************************************
  602. * CHECKBASESET()
  603. * Called by checkcommandprompt(), checkmailprompt(),
  604. * checkdescprompt()
  605. * Calls findstring()
  606. * Checks the base set of prompts.  Returns 1 if a prompt
  607. * was found; otherwise returns 0.
  608. *********************************************************************
  609. #endcomment
  610.  
  611. func checkbaseset : integer
  612. string LangPrompt, LangNumber, GraphicsPrompt, ScanPrompt
  613. string MorePrompt, ViewPrompt, CallingFrom, UserResp1, UserResp2
  614. string ContinuePrompt, UserPrompt1, UserPrompt2, BBSType
  615.     profilerd MailRun BBS "BBSType" BBSType
  616.     profilerd MailRun BBS "CallingFrom" CallingFrom
  617.     profilerd MailRun BBS "UserPrompt1" UserPrompt1
  618.     profilerd MailRun BBS "UserPrompt2" UserPrompt2
  619.     profilerd MailRun BBS "UserResp1" UserResp1
  620.     profilerd MailRun BBS "UserResp2" UserResp2
  621.     profilerd MailRun BBS "ContinuePrompt" ContinuePrompt
  622.     profilerd MailRun BBS "ScanPrompt" ScanPrompt
  623.     profilerd MailRun BBS "MorePrompt" MorePrompt
  624.     profilerd MailRun BBS "ViewPrompt" ViewPrompt
  625.     profilerd MailRun BBS "LangPrompt" LangPrompt
  626.     profilerd MailRun BBS "GraphicsPrompt" GraphicsPrompt
  627.     if findstring(prompt, UserPrompt1)
  628.         transmit UserResp1
  629.         transmit "^M"
  630.     elseif findstring(prompt, UserPrompt2)
  631.         transmit UserResp2
  632.         transmit "^M"
  633.     elseif findstring(prompt, ScanPrompt) || \
  634.         (findstring(prompt, MorePrompt) && !(findstring(BBSType, "WildCat")))
  635.         transmit "n^M"
  636.     elseif findstring(prompt, MorePrompt) && \
  637.         findstring(BBSType, "WildCat")
  638.         transmit "s^M"
  639.     elseif (findstring(prompt, ContinuePrompt) && \
  640.         findstring(BBSType, "PCBoard")) || \
  641.         findstring(prompt, CallingFrom)
  642.         transmit "y^M"
  643.     elseif findstring(prompt, ContinuePrompt) && \
  644.         !(findstring(BBSType, "PCBoard"))
  645.         transmit "^M"
  646.     elseif findstring(prompt, ViewPrompt)
  647.         if findstring(BBSType, "PCBoard") || findstring(BBSType, "WildCat")
  648.             transmit "n"
  649.         elseif findstring(BBSType, "RBBS")
  650.             transmit "q"
  651.         endif
  652.         transmit "^M"
  653.     elseif findstring(prompt, LangPrompt)
  654.         profilerd MailRun BBS "LangNumber" LangNumber
  655.         transmit LangNumber
  656.         transmit "^M"
  657.     elseif findstring(prompt, GraphicsPrompt)
  658.         profilerd MailRun BBS "GraphicsOn" GraphicsOn
  659.         if GraphicsOn == 0
  660.             transmit "n^M"
  661.         else
  662.             transmit "y^M"
  663.         endif
  664.     else
  665.         return 0
  666.     endif
  667.     return 1
  668. endfunc
  669.  
  670.  
  671. #comment
  672. *********************************************************************
  673. * HOLDING()
  674. * Called by getcommandprompt(), sendmail(), getmail(),
  675. * ulfile(), dlfile(), sendcommand()
  676. *
  677. * Calls capturescreen()
  678. * Jumps to ErrorFail in dobbs()
  679. * Stalls script while waiting for the result of a when
  680. * command.  Sends script to next BBS if there is a
  681. * timeout, or if carrier is lost.
  682. *********************************************************************
  683. #endcomment
  684.  
  685. proc holding
  686. string LastPrompt
  687.     IdleTimer = 1
  688.     holdstatus = 1
  689.     prompt = ""
  690.     xferstatus = $FILEXFER
  691.     while (IdleTimer < IdleTimeout) && (holdstatus == 1) && \
  692.         (xferstatus == 0) && $CARRIER
  693.         pause 1
  694.         termgets $ROW 0 prompt 79
  695.         if not strcmp prompt LastPrompt
  696.             ;if anything has been received, reset the timer
  697.             IdleTimer = 1
  698.         endif
  699.         LastPrompt = prompt
  700.         if !(IdleTimer % 15)
  701.             ;Send a carriage return every 15 seconds
  702.             transmit "^M"
  703.         endif
  704.         IdleTimer++
  705.         xferstatus = $FILEXFER
  706.     endwhile
  707.     if (IdleTimer == IdleTimeout) || ($CARRIER == 0)
  708.         ;If there has been a timeout, lost carrier or user escape...
  709.         clearwhen quiet
  710.         ;set FailCode and get out
  711.         capturescreen()
  712.         if IdleTimer == IdleTimeout
  713.             capturestr "`r`n`r`n*** Timed out waiting for prompt ***`r`n`r`n"
  714.         else
  715.             capturestr "`r`n`r`n*********** Lost carrier ***********`r`n`r`n"
  716.         endif
  717.         longjmp ErrorFail 1
  718.     endif
  719. endproc
  720.  
  721.  
  722. #comment
  723. *********************************************************************
  724. * ENDHOLD()
  725. * Releases a hold placed by holding()
  726. *********************************************************************
  727. #endcomment
  728.  
  729. proc endhold
  730.     holdstatus = 0
  731. endproc
  732.  
  733.  
  734. #comment
  735. *********************************************************************
  736. * WAITXFER()
  737. * Called by sendmail(), getmail(), ulfile(), dlfile()
  738. * Stalls script until a file transfer has been completed.
  739. *********************************************************************
  740. #endcomment
  741.  
  742. proc waitxfer
  743.     xferstatus = $FILEXFER
  744.     while xferstatus == 1
  745.         xferstatus = $FILEXFER
  746.     endwhile
  747. endproc
  748.  
  749.  
  750. #comment
  751. *********************************************************************
  752. * SENDMAIL()
  753. * Called by dobbs()
  754. * Calls checkmailprompt(), holding(), waitxfer(),
  755. * findstring(), makefullname(), getotherprompt(),
  756. * capturescreen()
  757. * Uploads a *.REP packet for the current BBS.
  758. *********************************************************************
  759. #endcomment
  760.  
  761. proc sendmail
  762. string MailULPrompt, MailXferProt, BBSType
  763. string ReplyFile, ReplyDir
  764. string Pending, temp
  765. integer j
  766.     profilerd MailRun BBS "BBSType" BBSType
  767.     profilerd MailRun "MailRun" "ReplyDir" ReplyDir
  768.     ReplyFile = makefullname(ReplyDir, BBS)
  769.     strcat ReplyFile ".REP"
  770.     if isfile ReplyFile
  771.         ;If there is a REP packet waiting...
  772.         if findstring(BBSType, "Auntie") || findstring(BBSType, "RBBS")
  773.             getotherprompt(GOTOMAIN)
  774.         endif
  775.         if findstring(BBSType, "Auntie")
  776.             transmit "QMU^M"
  777.         else
  778.             when quiet 1 call checkmailprompt
  779.             holding()
  780.             clearwhen quiet
  781.             transmit "u^M"
  782.         endif
  783.         profilerd MailRun BBS "MailULPrompt" MailULPrompt
  784.         when target 0 MailULPrompt call endhold
  785.         holding()
  786.         clearwhen target 0
  787.         set upldpath ReplyDir
  788.         profilerd MailRun BBS "MailXferProt" MailXferProt
  789.         sendfile MailXferProt ReplyFile
  790.         ;Hold until the transfer starts
  791.         holding()
  792.         ;Hold until the transfer finishes
  793.         waitxfer()
  794.         if xferstatus == 2
  795.             ;If upload was successful...
  796.             ;Rename the .REP packet as *.OLD
  797.             temp = ReplyFile
  798.             strlen temp j
  799.             j -= 3
  800.             strupdt temp "OLD" j 3
  801.             delfile temp
  802.             rename ReplyFile temp
  803.             ;Mark the Item as completed
  804.             Pending = "0"
  805.             ItemC++
  806.         else
  807.             ;Otherwise, mark it as an error
  808.             Pending = "2"
  809.             ItemE++
  810.             capturescreen()
  811.             capturestr "`r`n`r`n******* Error in File Transfer *******`r`n`r`n"
  812.         endif
  813.     else
  814.         Pending = "0"
  815.         ItemC++
  816.     endif
  817.     ;Update the *.MRN file
  818.     strupdt Item Pending 0 1
  819. endproc
  820.  
  821.  
  822. #comment
  823. *********************************************************************
  824. * GETMAIL()
  825. * Called by dobbs()
  826. * Calls checkmailprompt(), holding(), waitxfer, cleardir(),
  827. * renameqwk(), checkmail(), findstring(), makefullname(),
  828. * getotherprompt(), capturescreen()
  829. * Downloads a *.QWK packet for the current BBS.
  830. *********************************************************************
  831. #endcomment
  832.  
  833. proc getmail
  834. string MailFile, MailDLDir, MailDLPrompt, MailXferProt, CommandPrompt
  835. string Pending, temp, BBSType
  836.     profilerd MailRun BBS "BBSType" BBSType
  837.     foundstatus = 1
  838.     if findstring(BBSType, "Auntie") || findstring(BBSType, "RBBS") 
  839.         getotherprompt(GOTOMAIN)
  840.     endif
  841.     if findstring(BBSType, "Auntie")
  842.         transmit "QMD^M"
  843.     else
  844.         when quiet 1 call checkmailprompt
  845.         holding()
  846.         clearwhen quiet
  847.         transmit "d^M"
  848.         ;Wait for a prompt indicated presense of mail
  849.         when quiet 1 call checkmail
  850.         holding()
  851.         clearwhen quiet
  852.         if foundstatus == 0
  853.             Pending = "0"
  854.             ItemC++
  855.             strupdt Item Pending 0 1
  856.             return
  857.         endif
  858.         ;If there is mail...
  859.         transmit "y^M"
  860.     endif
  861.     ;Wait until asked to start the download
  862.     profilerd MailRun BBS "MailDLPrompt" MailDLPrompt
  863.     profilerd MailRun BBS "CommandPrompt" CommandPrompt
  864.     when target 0 MailDLPrompt call endhold
  865.     when target 1 CommandPrompt call killmaildl
  866.     holding()
  867.     clearwhen target 0
  868.     clearwhen target 1
  869.     ;If the command prompt has put in an appearance, abort the d/l
  870.     if foundstatus == 0
  871.         Pending = "0"
  872.         ItemC++
  873.         strupdt Item Pending 0 1
  874.         return
  875.     endif
  876.     ;Download to the mail download directory
  877.     MailDLDir = makefullname(MailRunDir, "MAILDL")
  878.     mkdir MailDLDir
  879.     cleardir(MailDLDir)
  880.     set dnldpath MailDLDir
  881.     strfmt temp "%s.QWK" BBS
  882.     profilerd MailRun BBS "MailXferProt" MailXferProt
  883.     getfile MailXferProt temp
  884.     ;Hold until the transfer starts
  885.     holding()
  886.     ;Hold until the transfer finishes
  887.     waitxfer()
  888.     if xferstatus == 2
  889.         ;If the download was successful...
  890.         ;Make sure the mail file has the ".QWK" extension.
  891.             ;This complicated workaround is the only way I could
  892.         ;figure out how to get the filename of a file that has
  893.         ;just been downloaded.
  894.         temp = makefullname(MailDLDir, "*.*")
  895.         findfirst temp
  896.         temp = makefullname(MailDLDir, $FILENAME)
  897.         MailFile = makefullname(MailDLDir, BBS)
  898.         strcat MailFile ".QWK"
  899.         rename temp MailFile
  900.         ;Renumber the QWK packets
  901.         renameqwk(MailFile)
  902.         ;and mark it as completed
  903.         Pending = "0"
  904.         ItemC++
  905.     else
  906.         ;Otherwise, mark the item as an error
  907.         Pending = "2"
  908.         ItemE++
  909.         capturescreen()
  910.         capturestr "`r`n`r`n***** Error in File Transfer *****`r`n`r`n"
  911.     endif
  912.     ;Delete the mail download directory
  913.     cleardir(MailDLDir)
  914.     chdir MailRunDir
  915.     rmdir MailDLDir
  916.     strupdt Item Pending 0 1
  917. endproc
  918.  
  919.  
  920. #comment
  921. *********************************************************************
  922. * CHECKMAIL()
  923. * Called by getmail()
  924. * Calls findstring(), endhold()
  925. * Checks prompt for presense of a mail packet.
  926. *********************************************************************
  927. #endcomment
  928.  
  929. proc checkmail
  930. string ReceiveQWKPrompt, MailPrompt
  931.     profilerd MailRun BBS "ReceiveQWKPrompt" ReceiveQWKPrompt
  932.     profilerd MailRun BBS "MailPrompt" MailPrompt
  933.     if findstring(prompt, MailPrompt)
  934.         foundstatus = 0
  935.         endhold()
  936.     elseif findstring(prompt, ReceiveQWKPrompt)
  937.         endhold()
  938.     endif
  939. endproc
  940.  
  941.  
  942. #comment
  943. *********************************************************************
  944. * KILLMAILDL()
  945. * Called by getmail()
  946. * If there is no mail packet, kills attempt to d/l.
  947. *********************************************************************
  948. #endcomment
  949.  
  950. proc killmaildl
  951.     foundstatus = 0
  952.     endhold()
  953. endproc
  954.  
  955.  
  956. #comment
  957. *********************************************************************
  958. * RENAMEQWK()
  959. * Called by getmail()
  960. * Calls makefullname()
  961. * Renames QWK packets after a successful mail download.
  962. *********************************************************************
  963. #endcomment
  964.  
  965. proc renameqwk
  966. strparm MailFile
  967. string OldMail1, OldMail2, MailDir
  968. string char
  969. integer i, j
  970.     profilerd MailRun "MailRun" "MailDir" MailDir
  971.     OldMail2 = makefullname(MailDir, BBS)
  972.     profilerd MailRun "MailRun" "SavePackets" i
  973.     ;max of 10 packets
  974.     if i > 10
  975.         i = 10
  976.     endif
  977.     i -= 1
  978.     if i > 0
  979.         strfmt OldMail2 "%s.QW%d" OldMail2 i
  980.     elseif i == 0
  981.         strfmt OldMail2 "%s.QW0" OldMail2
  982.     else
  983.         strfmt OldMail2 "%s.QWK" OldMail2
  984.     endif
  985.     ;Delete oldest file
  986.     delfile OldMail2
  987.     OldMail1 = OldMail2
  988.     strlen OldMail1 j
  989.     j -= 1
  990.     while i > 0
  991.         i--
  992.         itoa i char
  993.         strupdt OldMail1 char j 1
  994.         ;Rename the second oldest as the oldest
  995.         rename OldMail1 OldMail2
  996.         ;Rotate filenames
  997.         OldMail2 = OldMail1
  998.     endwhile
  999.     if i == 0
  1000.         ;if the oldest is QW0...
  1001.         strupdt OldMail1 "K" j 1
  1002.         rename OldMail1 OldMail2
  1003.         OldMail2 = OldMail1
  1004.     endif
  1005.     delfile OldMail2
  1006.     copyfile MailFile OldMail1
  1007.     delfile MailFile
  1008. endproc
  1009.  
  1010.  
  1011. #comment
  1012. *********************************************************************
  1013. * ULFILE()
  1014. * Called by dobbs()
  1015. * Calls getconfprompt(), getcommandprompt(), getotherprompt(),
  1016. * holding(), waitxfer(), checkdescprompt(), findstring(),
  1017. * checkverifyprompt(), gotuldlprompt(), senddesc(),
  1018. * capturescreen()
  1019. * Uploads a file to the current BBS.
  1020. *********************************************************************
  1021. #endcomment
  1022.  
  1023. proc ulfile
  1024. string Pending, ULPrompt, ULDescPrompt, UploadDir, XferProt
  1025. string FileName, BBSType
  1026.     profilerd MailRun BBS "BBSType" BBSType
  1027.     Pending = "2"
  1028.     strextract FileName Item "," 3
  1029.     strextract Conf item "," 4
  1030.     ;Change conferences if necessary
  1031.     getcommandprompt()
  1032.     if findstring(BBSType, "PCBoard") || findstring(BBSType, "WildCat")
  1033.         getconfprompt()
  1034.     endif
  1035.     if !(findstring(BBSType, "PCBoard"))
  1036.         getotherprompt(GOTOFILE)
  1037.     endif
  1038.     if findstring(BBSType, "WildCat")
  1039.         transmit "u^M"
  1040.         when quiet 1 call checkdescprompt
  1041.         holding()
  1042.         clearwhen quiet
  1043.     else
  1044.         transmit "u;"
  1045.     endif
  1046.     transmit FileName
  1047.     if findstring(BBSType, "Auntie")
  1048.         transmit ";n"
  1049.     endif
  1050.     transmit "^M"
  1051.     ;Check whether file is already on the board
  1052.     when quiet 1 call checkdescprompt
  1053.     holding()
  1054.     clearwhen quiet
  1055.     if foundstatus == 1
  1056.         if !(findstring(BBSType, "RBBS"))
  1057.             senddesc(FileName)
  1058.         endif
  1059.         if findstring(BBSType, "Auntie")
  1060.             when quiet 1 call checkverifyprompt
  1061.             holding()
  1062.             clearwhen quiet
  1063.         endif
  1064.         profilerd MailRun BBS "ULPrompt" ULPrompt
  1065.         when target 0 ULPrompt call gotuldlprompt
  1066.         when quiet 1 call checkdescprompt
  1067.         holding()
  1068.         clearwhen quiet
  1069.         clearwhen target 0
  1070.         xferstatus = 1
  1071.         profilerd MailRun "MailRun" "UploadDir" UploadDir
  1072.         set upldpath UploadDir
  1073.         profilerd MailRun BBS "XferProt" XferProt
  1074.         sendfile XferProt FileName
  1075.         ;Wait until the transfer starts
  1076.         holding()
  1077.         ;Wait until the transfer finishes
  1078.         waitxfer()
  1079.         if xferstatus == 2
  1080.             ;If the download was successful...
  1081.             if findstring(BBSType, "RBBS")
  1082.                 when quiet 1 call checkverifyprompt
  1083.                 holding()
  1084.                 clearwhen quiet
  1085.                 profilerd MailRun BBS "ULDescPrompt" ULDescPrompt
  1086.                 when target 0 ULDescPrompt call endhold
  1087.                 when quiet 1 call checkdescprompt
  1088.                 holding()
  1089.                 clearwhen quiet
  1090.                 clearwhen target 0
  1091.                 if foundstatus == 1
  1092.                     senddesc(FileName)
  1093.                     when quiet 1 call checkdescprompt
  1094.                     holding()
  1095.                     clearwhen quiet
  1096.                 endif
  1097.             endif
  1098.             ;Mark as completed
  1099.             Pending = "0"
  1100.             ItemC++
  1101.         else
  1102.             ;Otherwise, mark as an error
  1103.             ItemE++
  1104.             capturescreen()
  1105.             capturestr "`r`n`r`n***** Error in File Transfer *****`r`n`r`n"
  1106.         endif
  1107.     else
  1108.         ;If the file was already on the board
  1109.         ;Send a carriage return to get the prompt back
  1110.         transmit "^M"
  1111.         if findstring(BBSType, "WildCat")
  1112.             pause 1
  1113.             transmit "A^M"
  1114.         endif
  1115.         ItemC++
  1116.     endif
  1117.     strupdt Item Pending 0 1
  1118. endproc
  1119.  
  1120.  
  1121. #comment
  1122. *********************************************************************
  1123. * CHECKVERIFYPROMPT()
  1124. * Called by ulfile()
  1125. * Calls findstring(), endhold()
  1126. * Checks for prompt to send the category or file area to
  1127. * which a file should be uploaded.
  1128. *********************************************************************
  1129. #endcomment
  1130.  
  1131. proc checkverifyprompt
  1132. string BBSType
  1133.     profilerd MailRun BBS "BBSType" BBSType
  1134.     if findstring(BBSType, "Auntie") && findstring(prompt, "editor function")
  1135.         transmit "s^M"
  1136.     elseif findstring(prompt, "category")
  1137.         transmit Conf
  1138.         if findstring(BBSType, "Auntie")
  1139.             transmit ";y;n^M"
  1140.         endif
  1141.         endhold()
  1142.     endif
  1143. endproc
  1144.  
  1145.  
  1146. #comment
  1147. *********************************************************************
  1148. * SENDDESC()
  1149. * Called by ulfile()
  1150. * Calls checkfile(), makefullname(), openfile(), interfaceon(),
  1151. * interfaceoff(), findstring()
  1152. * Sends the file description of a file to be uploaded;
  1153. * otherwise sends "Description not available".
  1154. *********************************************************************
  1155. #endcomment
  1156.  
  1157. proc senddesc
  1158. strparm FileName
  1159. string UDXString, UDXFile, MRunUDX, MRunUBF, BBSType
  1160. string DB, DL
  1161. integer char
  1162. long DescBegin, DescLength
  1163. long counter
  1164.     profilerd MailRun BBS "BBSType" BBSType
  1165.     MRunUDX = makefullname(MailRunDir, "MAILRUN.UDX")
  1166.     MRunUBF = makefullname(MailRunDir, "MAILRUN.UBF")
  1167.     ;If the file is not on the board, send a description
  1168.     if checkfile(MRunUDX) && checkfile(MRunUBF)
  1169.         interfaceoff()
  1170.         openfile(MRunUBFFile, MRunUBF, _READWRITE, _NORMAL)
  1171.         openfile(MRunUDXFile, MRunUDX, _READWRITE, _TEXT)
  1172.         fgets MRunUDXFile UDXString
  1173.         strextract UDXFile UDXString "`t" 0
  1174.         while not strcmpi UDXFile FileName
  1175.             fgets MRunUDXFile UDXString
  1176.             strextract UDXFile UDXString "`t" 0
  1177.         endwhile
  1178.         strextract DB UDXString "`t" 4
  1179.         strextract DL UDXString "`t" 5
  1180.         atol DB DescBegin
  1181.         atol DL DescLength
  1182.         if findstring(BBSType, "WildCat")
  1183.             if DescLength > 60
  1184.                 DescLength = 60
  1185.             endif
  1186.         endif
  1187.         if findstring(BBSType, "RBBS")
  1188.             if DescLength > 45
  1189.                 DescLength = 45
  1190.             endif
  1191.         endif
  1192.         fseek MRunUBFFile DescBegin 0
  1193.         for counter = 1 upto DescLength
  1194.             fgetc MRunUBFFile char
  1195.             computc char
  1196.         endfor
  1197.         fclose MRunUBFFile
  1198.         fclose MRunUDXFile
  1199.         interfaceon()
  1200.     else
  1201.         transmit "Description not available"
  1202.     endif
  1203.     transmit "^M"
  1204.     if findstring(BBSType, "PCBoard") || findstring(BBSType, "Auntie")
  1205.         transmit "^M"
  1206.     endif
  1207. endproc
  1208.  
  1209.  
  1210. #comment
  1211. *********************************************************************
  1212. * DLFILE()
  1213. * Called by dobbs()
  1214. * Calls getconfprompt(), getcommandprompt(), getotherprompt(),
  1215. * holding(), waitxfer(), putdesc(), findstring(),
  1216. * checkdescprompt(), gotuldlprompt(), capturescreen()
  1217. * Downloads a file from the current BBS.
  1218. *********************************************************************
  1219. #endcomment
  1220.  
  1221. proc dlfile
  1222. string Pending, DLPrompt, DownloadDir, XferProt, FileName, BBSType
  1223.     profilerd MailRun BBS "BBSType" BBSType
  1224.     strextract FileName Item "," 3
  1225.     strextract Conf Item "," 4
  1226.     ;Change conferences if necessary
  1227.     getcommandprompt()
  1228.     if !(findstring(BBSType, "Auntie"))
  1229.         getconfprompt()
  1230.     endif
  1231.     if !(findstring(BBSType, "PCBoard"))
  1232.         getotherprompt(GOTOFILE)
  1233.     endif
  1234.     if findstring(BBSType, "WildCat")
  1235.         transmit "d^M"
  1236.         when quiet 1 call checkdescprompt
  1237.         holding()
  1238.         clearwhen quiet
  1239.     else
  1240.         transmit "d;"
  1241.     endif
  1242.     transmit FileName
  1243.     transmit "^M"
  1244.     ;Check whether file is available for d/l
  1245.     profilerd MailRun BBS "DLPrompt" DLPrompt
  1246.     when target 0 DLPrompt call gotuldlprompt
  1247.     when quiet 1 call checkdescprompt
  1248.     holding()
  1249.     clearwhen quiet
  1250.     clearwhen target 0
  1251.     if foundstatus == 1
  1252.         ;If it is available...
  1253.         profilerd MailRun "MailRun" "DownloadDir" DownloadDir
  1254.         set dnldpath DownloadDir
  1255.         profilerd MailRun BBS "XferProt" XferProt
  1256.         getfile XferProt FileName
  1257.         ;Wait until the transfer starts
  1258.         holding()
  1259.         ;Wait until the transfer finishes
  1260.         waitxfer()
  1261.         if xferstatus == 2
  1262.             ;If the download was successful...
  1263.             putdesc(FileName)
  1264.             ;Mark as completed
  1265.             Pending = "0"
  1266.             ItemC++
  1267.         else
  1268.             ;Otherwise, mark as an error
  1269.             Pending = "2"
  1270.             ItemE++
  1271.             capturescreen()
  1272.             capturestr "`r`n`r`n*** Error in File Transfer ***`r`n`r`n"
  1273.         endif
  1274.     else
  1275.         ;If file was unavailable, mark as error.
  1276.         Pending = "2"
  1277.         ItemE++
  1278.         ;Send a return to get the prompt back.
  1279.         transmit "^M"
  1280.     endif
  1281.     strupdt Item Pending 0 1
  1282. endproc
  1283.  
  1284.  
  1285. #comment
  1286. *********************************************************************
  1287. * PUTDESC()
  1288. * Called by dlfile()
  1289. * Calls openfile(), checkfile(), interfaceoff(), interfaceon(),
  1290. * makefullname()
  1291. * Searches the BBSs .IDX file for a file description and
  1292. * copies the description from the .DBF file to the uplaod
  1293. * files database.  If no description is found, a line
  1294. * including the file name, size and date is put in the
  1295. * upload files index.
  1296. *********************************************************************
  1297. #endcomment
  1298.  
  1299. proc putdesc
  1300. strparm FileName
  1301. string DB, DL, idxString, MRunUDX, MRunUBF, BBSidx, BBSdbf
  1302. string idxFile, idxDesc, FileDate, FullFileName, DownloadDir
  1303. integer inidx, char
  1304. long DescBegin, DescLength, counter, FileSize
  1305.     interfaceoff()
  1306.     ;Determine whether the BBS index and database files exist
  1307.     BBSidx = makefullname(MailRunDir, BBS)
  1308.     strfmt BBSdbf "%s.DBF" BBSidx
  1309.     strcat BBSidx ".IDX"
  1310.     inidx = 0
  1311.     if checkfile(BBSidx) && checkfile(BBSdbf)
  1312.         ;If both files exist...
  1313.         openfile(BBSidxFile, BBSidx, _READWRITE, _TEXT)
  1314.         fgets BBSidxFile idxString
  1315.         while not feof BBSidxFile
  1316.             ;Loop through the index file and stop if the file is found
  1317.             strextract idxFile idxString "`t" 0
  1318.             if strcmpi FileName idxFile
  1319.                 inidx = 1
  1320.                 exitwhile
  1321.             endif
  1322.             fgets BBSidxFile idxString
  1323.         endwhile
  1324.         fclose BBSidxFile
  1325.     endif
  1326.     strlwr FileName
  1327.     ;Get the file size and date
  1328.     profilerd MailRun "MailRun" "DownloadDir" DownloadDir
  1329.     FullFileName = makefullname(DownloadDir, FileName)
  1330.     getfsize FullFileName FileSize
  1331.     getfdate FullFileName FileDate
  1332.     ;Determine whether the upload index and database files exist
  1333.     MRunUDX = makefullname(MailRunDir, "MAILRUN.UDX")
  1334.     MRunUBF = makefullname(MailRunDir, "MAILRUN.UBF")
  1335.     if checkfile(MRunUBF) && checkfile(MRunUDX)
  1336.         ;If both files exist, open them
  1337.         openfile(MRunUBFFile, MRunUBF, _READWRITE, _NORMAL)
  1338.         openfile(MRunUDXFile, MRunUDX, _READWRITE, _NORMAL)
  1339.     else
  1340.         ;Otherwise, create them
  1341.         openfile(MRunUBFFile, MRunUBF, _CREATE, _NORMAL)
  1342.         openfile(MRunUDXFile, MRunUDX, _CREATE, _NORMAL)
  1343.     endif
  1344.     fseek MRunUDXFile 0 2
  1345.     if inidx == 1
  1346.         ;If the file was found in the BBS index...
  1347.         strextract idxDesc idxString "`t" 3
  1348.         ;Get the descriptions starting point and length...
  1349.         strextract DB idxString "`t" 4
  1350.         strextract DL idxString "`t" 5
  1351.         atol DB DescBegin
  1352.         atol DL DescLength
  1353.         openfile(BBSdbfFile, BBSdbf, _READWRITE, _NORMAL)
  1354.         fseek BBSdbfFile DescBegin 0
  1355.         fseek MRunUBFFile 0 2
  1356.         ftell MRunUBFFile DescBegin
  1357.         ;And copy each character of the description to the upload database
  1358.         for counter = 1 upto DescLength
  1359.             fgetc BBSdbfFile char
  1360.             fputc MRunUBFFile char
  1361.         endfor
  1362.         fclose BBSdbfFile
  1363.         ;Format the upload index entry
  1364.         fstrfmt MRunUDXFile "%s`t%ld`t%s`t%s`t%ld`t%ld`r`n" \
  1365.             FileName FileSize FileDate idxDesc DescBegin DescLength
  1366.     else
  1367.         ;If there was no entry in the BBS index...
  1368.         ;Format the upload index entry
  1369.         fstrfmt MRunUDXFile "%s`t%ld`t%s`t`t0`t0`r`n" FileName FileSize FileDate
  1370.     endif
  1371.     fclose MRunUBFFile
  1372.     fclose MRunUDXFile
  1373.     interfaceon()
  1374. endproc
  1375.  
  1376.  
  1377. #comment
  1378. *********************************************************************
  1379. * SENDCOMMAND()
  1380. * Called by dobbs()
  1381. * Calls getcommandprompt(), getotherprompt(), holding(), 
  1382. * findstring()
  1383. * Sends commands to the current BBS.  A command item may
  1384. * contain multiple command lines separated by a vertical
  1385. * bar.  The script will send these one at a time, waiting
  1386. * until the terminal has been quiet for 15 seconds before
  1387. * sending the next one.  The command must return the user
  1388. * to the Main Command Prompt, or be the last item for the
  1389. * BBS.
  1390. *********************************************************************
  1391. #endcomment
  1392.  
  1393. proc sendcommand
  1394. string CommandLine, Command, BBSType
  1395. integer j
  1396.     getcommandprompt()
  1397.     profilerd MailRun BBS "BBSType" BBSType
  1398.     if !(findstring(BBSType, "PCBoard"))
  1399.         getotherprompt(GOTOMAIN)
  1400.     endif
  1401.     strextract Command Item "," 3
  1402.     j = 0
  1403.     strextract CommandLine Command "|" j
  1404.     while not NULLSTR CommandLine
  1405.         if j != 0
  1406.             when quiet 10 call endhold
  1407.             holding()
  1408.             clearwhen quiet
  1409.         endif
  1410.         transmit CommandLine
  1411.         transmit "^M"
  1412.         j++
  1413.         strextract CommandLine Command "|" j
  1414.     endwhile
  1415.     strupdt Item "0" 0 1
  1416. endproc
  1417.  
  1418.  
  1419. #comment
  1420. *********************************************************************
  1421. * SENDSCRIPT()
  1422. * Called by dobbs()
  1423. * Calls getcommandprompt(), getotherprompt(), mailrunbox(),
  1424. * findstring(), makefullname()
  1425. * Executes a script file.  The script must return to the
  1426. * Main Command Prompt, or be the last item for that BBS.
  1427. *********************************************************************
  1428. #endcomment
  1429.  
  1430. proc sendscript
  1431. string ScriptName, BBSType
  1432.     getcommandprompt()
  1433.     profilerd MailRun BBS "BBSType" BBSType
  1434.     if !(findstring(BBSType, "PCBoard"))
  1435.         getotherprompt(GOTOMAIN)
  1436.     endif
  1437.     strextract ScriptName Item "," 3
  1438.     ScriptName = makefullname(MailRunDir, ScriptName)
  1439.     execute ScriptName
  1440.     strupdt Item "0" 0 1
  1441.     mailrunbox()
  1442. endproc
  1443.  
  1444.  
  1445. #comment
  1446. *********************************************************************
  1447. * LOGOFF()
  1448. * Called by dobbs()
  1449. * Logs off the current BBS.
  1450. *********************************************************************
  1451. #endcomment
  1452.  
  1453. proc logoff
  1454. integer i = 1
  1455.     if $CARRIER
  1456.         transmit "g^M"
  1457.     endif
  1458.     pause 5
  1459.     while $CARRIER && (i < 3)
  1460.         hangup
  1461.         pause 5
  1462.         i++
  1463.     endwhile
  1464. endproc
  1465.  
  1466.  
  1467. #comment
  1468. *********************************************************************
  1469. * MAILRUNBOX()
  1470. * Called by main(), sendscript()
  1471. * Draws the main MailRun dialog box.
  1472. *********************************************************************
  1473. #endcomment
  1474.  
  1475. proc mailrunbox
  1476. destroydlg
  1477. MainBoxTabs = "20,30,220,230,233,236,239,242"
  1478. HelpPage = 2
  1479. dialogbox 8 36 346 181 15 "MailRun" HELPID HelpPage
  1480.    groupbox 10 33 228 135 "Task List" shadow
  1481.    flistbox 15 52 218 102 TaskList MainBoxTabs single TaskItem
  1482.    text  15 153 49 8 left "# = permanent"
  1483.    text  76 153 49 8 left "ñ = temporary"
  1484.    text  140 153 33 8 left "! = error"
  1485.    text  182 153 53 8 left "@ = completed"
  1486.    groupbox 244 33 90 135 "Statistics" shadow
  1487.    text  248 55 62 8 right "BBSs in mailrun:"
  1488.    text  248 69 62 8 right "BBSs completed:"
  1489.    text  248 83 62 8 right "BBSs left to call:"
  1490.    text  248 97 62 8 right "Items in mailrun:"
  1491.    text  248 111 62 8 right "Items completed:"
  1492.    text  248 125 62 8 right "Item errors:"
  1493.    text  248 139 62 8 right "Items remaining:"
  1494.    text  248 153 62 8 right "Dialing Attempt:"
  1495.    vtext 314 55 16 9 left BBSTotal
  1496.    vtext 314 69 16 9 left BBSComplete
  1497.    vtext 314 83 16 9 left BBSRemaining
  1498.    vtext 314 97 16 9 left ItemTotal
  1499.    vtext 314 111 16 9 left ItemComplete
  1500.    vtext 314 125 16 9 left ItemError
  1501.    vtext 314 139 16 9 left ItemRemaining
  1502.    vtext 314 153 16 9 left AttemptNum
  1503.    text  102 14 74 8 right "The current mailrun is:"
  1504.    combobox 180 12 76 41 MailRunTrunc MailRunTrunc
  1505.    pushbutton 0 0 0 0 "          &t" normal default
  1506.    pushbutton 0 0 0 0 "          &u" normal
  1507.    pushbutton 0 0 0 0 "          &i" normal
  1508. enddialog
  1509. disable CTRL 170
  1510. endproc
  1511.  
  1512.  
  1513. #comment
  1514. *********************************************************************
  1515. * CAPTURESCREEN()
  1516. * Called by main(), holding(), sendmail(), getmail(),
  1517. * ulfile(), dlfile()
  1518. * Puts the current screen in the capture file.  Normally, the
  1519. * contents of a terminal screen are not placed in the capture
  1520. * file until they scroll off.  If a capture string is placed in
  1521. * a capture file, it will appear before the last screenfull of
  1522. * data.  This procedure is necessary to ensure that a capture
  1523. * string appears after all data that has already been received
  1524. * from the remote.
  1525. *********************************************************************
  1526. #endcomment
  1527.  
  1528. proc capturescreen
  1529. string RowString
  1530. integer Row, MaxRows, MaxCols
  1531.     fetch terminal rows MaxRows
  1532.     fetch terminal columns MaxCols
  1533.     for Row = 0 upto MaxRows
  1534.         termgets Row 0 RowString MaxCols
  1535.         capturestr RowString
  1536.         capturestr "`r`n"
  1537.     endfor
  1538.     termreset
  1539. endproc
  1540.         
  1541.